<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<!--<script src="/public/transcode.js"></script>-->
<script>
    var code = getQueryString('code');
    var nowdomain = getQueryString('nowdomain');
    // var transcode = new TransCode();
    // var headers = transcode.headers(1);
    if (nowdomain&&nowdomain!=window.location.href){
        window.location.replace(nowdomain+'/public/transit/getWechatCode.html?code='+code);
    } else{
        ajaxFun({
            url: '/member/Wechatpubliclogin/getWechatInfo',
            type: 'post',
            // headers: headers,
            data:{code:code},
            // data:{tm_encrypt_data:transcode.encrypt({code:code})},
            cache: false,  //禁用缓存
            dataType: 'json',
            success: function (data) {
                if (data.tmencrypt==1){
                    data.data =  transcode.decrypt(data.data);
                }
                if (data.code==200){
                    window.localStorage.setItem('user_openid',data.data.extra.openid);
                    window.localStorage.setItem('tm_userInfo',JSON.stringify(data.data));
                    window.localStorage.setItem('user_mobile_token',data.data.token);
                    window.sessionStorage.setItem('user_mobile_token',data.data.token);
                    window.localStorage.setItem('vote_activity_token',JSON.stringify({type:'string',data:data.data.token}));
                    window.localStorage.setItem('member_code',data.data.member_info.member_code);
                    window.sessionStorage.setItem('member_code',data.data.member_info.member_code);
                    window.location.replace(window.sessionStorage.getItem('toUrl'));
                } else{
                    alert(data.msg);
                }
            },
            error:function(){

            }
        });
    };

    function ajaxFun(){
        var ajaxData = {
            type:arguments[0].type || "GET",
            url:arguments[0].url || "",
            async:arguments[0].async || "true",
            data:arguments[0].data || null,
            dataType:arguments[0].dataType || "text",
            contentType:arguments[0].contentType || "application/x-www-form-urlencoded",
            headers: arguments[0].headers || {},
            beforeSend:arguments[0].beforeSend || function(){},
            success:arguments[0].success || function(){},
            error:arguments[0].error || function(){}
        }
        ajaxData.beforeSend()
        var xhr = createxmlHttpRequest();
        xhr.responseType=ajaxData.dataType;
        xhr.open(ajaxData.type,ajaxData.url,ajaxData.async);
        xhr.setRequestHeader("Content-Type",ajaxData.contentType);
        for(var i in ajaxData.headers ){
            xhr.setRequestHeader(i,ajaxData.headers[i]);
        }
        xhr.send(convertData(ajaxData.data));
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4) {
                if(xhr.status == 200){
                    ajaxData.success(xhr.response)
                }else{
                    ajaxData.error()
                }
            }
        }
    }
    function createxmlHttpRequest() {
        if (window.ActiveXObject) {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } else if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        }
    }
    function convertData(data){
        if( typeof data === 'object' ){
            var convertResult = "" ;
            for(var c in data){
                convertResult+= c + "=" + data[c] + "&";
            }
            convertResult=convertResult.substring(0,convertResult.length-1);
            return convertResult;
        }else{
            return data;
        }
    }
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURI(r[2]);
        return null;
    }
</script>
</body>
</html>